<?php
declare(strict_types=1);
namespace Dao;
// hook dao_auth_user_grid_rule_use.php

use Model\AuthUserGridRuleModel;

class AuthUserGridRuleDao extends AuthUserGridRuleModel
{
	// hook dao_auth_user_grid_rule_public_start.php

	protected array $add_rule	=	[];
    protected array $edit_rule	=	[];

    protected array $rule	=	[
		/*
		"mobile"=>[
			"max"=>3
			"min"=>3
			"func"=>'isMobile'
			"error"=>false,
			'message'=>'格式有误'
		],
		"username"=>[
			"max"=>3
			"min"=>3
			"func"=>'checkS'
			"error"=>false,
			'message'=>'格式有误'
		],
		*/
	];
	//数据，字段，验证规则
	/*
	function isMobile($data,$field,$val){
	
		return true;
	}
	*/
	
	// hook dao_auth_user_grid_rule_public_end.php

    public function get($UserID,$grid,$key){
        $data = $this->read(['UserID'=>$UserID,'GridName'=>$grid,'GridKey'=>$key]);
        return $data;
    }
    public function gets($UserID,$grid){
        $data = $this->select(['UserID'=>$UserID,'GridName'=>$grid]);
        return $data;
    }
    public function del($UserID,$grid,$key){
        $data = $this->delete(['UserID'=>$UserID,'GridName'=>$grid,'GridKey'=>$key]);
        return $data;
    }

    public function set($UserID,$grid,$key,$v){
        $data = $this->get($UserID,$grid,$key);
        if(empty($data['UserID'])){
            $this->insert(['UserID'=>$UserID,'GridName'=>$grid,'GridKey'=>$key,'Config'=>$v]);
        }else{
            $this->update(['UserID'=>$UserID,'GridName'=>$grid,'GridKey'=>$key],['Config'=>$v]);
        }
    }

	// hook dao_auth_user_grid_rule_end.php
}
?>